package com.xgp.order.controller;

import com.xgp.order.bean.Order;
import com.xgp.order.service.OrderService;
import com.xgp.order.yamls.OrderYaml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@RefreshScope // 配置中心更改后自动刷新
@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    OrderService orderService;

//    获取配置中心的配置（推荐抽离）
//    @Value("${order.timeout}")
//    String orderTimeout;
//    @Value("${order.auto-confirm}")
//    String orderAutoConfirm;

    @Autowired
    OrderYaml orderYaml;

    //返回获取配置的值
    @GetMapping("/config")
    public String config() {
        System.out.println(orderYaml);
        return orderYaml.getTimeout() + "---" + orderYaml.getAutoConfirm();
    }


    // 创建订单
    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId,
                             @RequestParam("productId") Long productId) {
        return orderService.createOrder(productId,userId);
    }
}
